package com.example.tests;

import static com.example.tests.ContactDataGenerator.loadContactsFromXmlFile;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.example.fw.ContactHelper;
import com.example.utils.SortedListOf;

public class ContactCreation_tests extends TestBase {

	@DataProvider
	public Iterator<Object[]> contactsFromFile() throws IOException {
		return wrapContactsForDataprovider(loadContactsFromXmlFile(new File("contacts.xml"))).iterator();
	}

	@Test (dataProvider = "contactsFromFile")
	public void createContactWithValidData(ContactData contact) throws Exception {
		ContactHelper contactHelper = app.getContactHelper();		
		//save old state
		SortedListOf<ContactData> oldContactList = contactHelper.getContacts();
		
		//actions
		contactHelper.createContact(contact);
		
		//save new state
		SortedListOf<ContactData> newContactList = contactHelper.getContacts();
		//compare states
	
		assertThat(newContactList, equalTo(oldContactList.withAdded(contact)));
	}

}